import java.util.*;
public class Chromosome
{	
	private BitSet bitset = new BitSet(Data.CHROMOSOME_SIZE );
	private Chromosome()
	{	
	}
	public Chromosome(BitSet bitset) {
		this.bitset = bitset;
	}
	public BitSet getBitset() {
		return bitset;
	}
	public Fenotipe getFenotipe()
	{
		HashSet<Integer>[] sets = new HashSet[2];
		sets[0] = new HashSet<Integer>();
		sets[1] = new HashSet<Integer>();
		int[][] trucks = new int[7][3];
		int dayMask = 0;
						
		BitSet buildings =  this.bitset.get(0,50);
		for (int b = 0; b < Data.TOTAL_BUILDINGS; b++)
			if( !buildings.get(b) )
				sets[0].add(b);
			else
				sets[1].add(b);
		BitSet days = this.bitset.get(50,57);		
		for (int day = 0, init = 57; day < 7; day++ , init += 12)
		{
			dayMask |= (days.get(day)) ? (1<<day) : 0; 
			for (int truckType = 0,from = init; truckType < 3; truckType++,from+=4)
				trucks[day][truckType] = Integer.parseInt(Util.toString( this.bitset.get(from,from+4) , 4 ) , 2 ); 			
		}		
		return new Fenotipe(sets, trucks, dayMask);
	}
	public String toString()
	{
		StringBuilder sb = new StringBuilder();		
		sb.append(Util.toString( this.bitset.get(0,50) , 50)+"-");		
		sb.append(Util.toString( this.bitset.get(50,57) , 7)+"-");		
		for (int day = 0, init = 57; day < 7; day++ , init += 12)
		{
			sb.append("[");
			StringBuilder sb2 = new StringBuilder();
			for (int truckType = 0,from = init; truckType < 3; truckType++,from+=4)				
				sb2.append(Util.toString( this.bitset.get(from,from+4) , 4 )+" ");
			sb.append(sb2.toString().trim());
			sb.append("]");
		}		
		return sb.toString();
	}	
}
